package com.wb.iec104.utils;

/**
 * @author HR
 */
public class HexConvert {
    public static String BinaryToHexString(byte[] bytes) {

        String hexStr = "0123456789ABCDEF";

        String result = "";

        String hex = "";

        for (byte b : bytes) {

            hex = String.valueOf(hexStr.charAt((b & 0xF0) >> 4));

            hex += String.valueOf(hexStr.charAt(b & 0x0F));

            result += hex + " ";

        }

        return result;

    }
    public static short bytes2Short2(byte[] b) {

        short i = (short) (((b[1] & 0xff) << 8) | b[0] & 0xff);

        return i;

    }

    /**
     * 日志报文转化成解析格式
     * 日志报文 68 28 1e  c  0  0 24  2  3  1  1  0 7a 45  0 1c c7 b1 3c  0 c0 24  0  0 15  3 16 7b 45  0 55 55  5 bc  0 c0 24  0  0 15  3 16
     * 返回格式 不足2位的补0
     * @param str
     * @return
     */
    public static String strToString(String str){
        String[] array = str.split("  ");
        StringBuffer sb =new StringBuffer(array[0]);
        for(int index=1;index<array.length;index++){
            sb.append(0).append(array[index]);
        }
        return sb.toString();
    }
}
